<%@ page import="entity.User" %>
<%@ page import="java.util.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--引入核心标签库--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--引入格式化标签库--%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--引入自定义标签库--%>
<%@ taglib prefix="mm" uri="/mytaglib"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
//    request.setAttribute("key","lisi");
//    if (5 == 5) {
//        System.out.println("true");
//    } else {
//        System.out.println("false");
//    }
%>

<c:set scope="request" var="key" value="lisi"/>
${key}
<c:if test="${5 < 5}">
    5==5
</c:if>

<c:set scope="request" var="height" value="200"/>
<c:choose>
    <%-- 这是 html 注释 --%>
    <c:when test="${ requestScope.height > 190 }">
        <h2>小巨人</h2>
    </c:when>
    <c:when test="${ requestScope.height > 180 }">
        <h2>很高</h2>
    </c:when>
    <c:when test="${ requestScope.height > 170 }">
        <h2>还可以</h2>
    </c:when>
    <c:otherwise>
        <c:choose>
            <c:when test="${requestScope.height > 160}">
                <h3>大于 160</h3>
            </c:when>
            <c:when test="${requestScope.height > 150}">
                <h3>大于 150</h3>
            </c:when>
            <c:when test="${requestScope.height > 140}">
                <h3>大于 140</h3>
            </c:when>
            <c:otherwise>
                其他小于 140
            </c:otherwise>
        </c:choose>
    </c:otherwise>
</c:choose>

<%--遍历--%>
<%
    for (int i = 0; i < 10; i++) {
%>
<%=i%>
<%
    }
%>
<br>
<c:forEach begin="0" end="9" var="i" varStatus="status">
    ${i}
</c:forEach>

<% // 数组
    request.setAttribute("arr",new String[]{"lisi","wangwu"});
    // map
    Map<String, Object> map = new HashMap<>();
    map.put("map1","li");
    map.put("map2","wang");
    request.setAttribute("map",map);

    // list
    List<User> users = new ArrayList<>();
    for (long i = 0; i < 10; i++) {
        users.add(new User(i, "username" + i, "password" + i));
    }
    request.setAttribute("users",users);
%>
<c:forEach items="${requestScope.arr}" var="a">
    ${a}
</c:forEach>
<br>
<c:forEach items="${requestScope.map}" var="m">
    ${m}<br>
    ${m.key}:${m.value}
</c:forEach>
<br>
<table border="1" cellspacing="0">
    <tr>
        <th>序号</th>
        <th>id</th>
        <th>username</th>
        <th>password</th>
    </tr>
    <c:forEach items="${requestScope.users}" var="u" begin="2" end="9" step="2" varStatus="status">
        <tr>
            <td>${status.count}</td>
            <td>${u.id}</td>
            <td>${u.username}</td>
            <td>${u.password}</td>
        </tr>
    </c:forEach>
</table>
<br>
<%
request.setAttribute("num",99.9999999);
    Date date = new Date();
    date.setHours(20);
    request.setAttribute("date",date);
%>
<fmt:formatNumber value="${requestScope.num}" type="percent"/>
<fmt:formatNumber value="${requestScope.num}" type="number"/>
<fmt:formatNumber value="${requestScope.num}" type="currency"/>
<fmt:formatNumber value="${requestScope.num}" pattern="#.0000"/>

<fmt:formatDate value="${requestScope.date}" pattern="yyyy-MM-dd"/><br>
<fmt:formatDate value="${requestScope.date}" pattern="yyyy-M-d"/><br>
<fmt:formatDate value="${requestScope.date}" pattern="hh:mm:ss"/><br>
<fmt:formatDate value="${requestScope.date}" pattern="yyyy-MM-dd HH:mm:ss"/><br>

<br>
<mm:hello/>
<mm:message key="hello.title"/>
<br>
<%--上传--%>
<form action="${pageContext.request.contextPath}/upload" method="post" enctype="multipart/form-data">
    <input  type="text" name="username"/><br>
    <input  type="file" name="file"/>
    <input type="submit" />
</form>
</body>
</html>
